using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;

using CNCSoft.EWinform;
using CNCSoft.EWinform.ControlUtils;
//using CNCSoft.EWinform.ERPApps;
using CNCSoft.EWinform.AGrid;
using CNCSoft.EData;

using Common;

namespace CNCSoft.ErpApps.TMS {

	/// <summary>
	/// Summary description for TienMatPhieuThuData.
	/// </summary>
	public class frmBrowseData: TMSDataBase  {

		public enum TL  {
            DanhMuc
        }
        
        public frmBrowseData()
        {
            ds.Tables.Add("DANHMUC");
		}


        public void fill(string strSQL_SELECT)
        {
            try
            {
                SQLHelper.Fill(getTable(TL.DanhMuc), GlobalVariable.WSInfo.ConnectionString, strSQL_SELECT);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Fill datasource");
            }
        }

      	public bool update(string strSQL_UPDATE) {
			try {
                SqlConnection sqlcn = new SqlConnection(GlobalVariable.WSInfo.ConnectionString);
                sqlcn.Open();
                SqlTransaction sqltran = sqlcn.BeginTransaction();
                SqlDataAdapter sqldaD = new SqlDataAdapter(strSQL_UPDATE, sqlcn);
                
                try
                {
                    DataHelper.buildDataCommands(ref sqldaD, ref sqltran);
                    sqldaD.Update(getDataSet(), "DANHMUC");
                    sqltran.Commit();
                }
                catch (Exception ex)
                {
                    try
                    {
                        sqltran.Rollback();
                    }
                    catch { }
                    throw ex;
                }
                finally
                {
                    try
                    {
                        sqltran.Rollback();
                        sqlcn.Close();
                        sqltran.Dispose();
                        sqlcn.Dispose();
                        sqldaD.Dispose();
                    }
                    catch { }
                } 
                ds.AcceptChanges();
				return true;

			} catch (Exception ex) {
				MessageBox.Show(RS.ERROR_UPDATE +"\n" +ex.Message, RS.ERROR_UPDATE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
			return false;
		}
        

		public DataTable getTable(TL index) {
			return ds.Tables[(int)index];
		}
         

	}
}
